package com.nacrtstudio.webgiftshop.pages;

import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.nacrtstudio.webgiftshop.facade.Controller;
import com.nacrtstudio.webgiftshop.model.shop.Address;
import com.nacrtstudio.webgiftshop.model.shop.User;
import com.nacrtstudio.webgiftshop.model.shop.beans.AddressBean;

public class EnterAddress {
	@Inject
	private Controller controller;
	@Property
	private Address address;
	@Property
	private User user;
	
	void onActivate() {
		try {
			user = controller.getLoggedUser();
			if (user.getAddress()!=null) {
				address = controller.getLoggedUser().getAddress();
			} else {
				address = new AddressBean();
			}
		} catch (Exception e) {
			System.out.println("---"+e);
		}
	}
	
	public boolean isLoggedIn(){
		return controller.isLoggedIn();
	}
	
	Object onSuccess(){
		user.setAddress(address);
		controller.updateUser(user);
		return UserProfile.class;
	}
}
